package com.irdstudio.efp.esb.service.impl.hj;

import com.alibaba.fastjson.JSONObject;
import com.irdstudio.basic.framework.core.exception.ESBException;
import com.irdstudio.efp.esb.common.client.resp.EsbRespServiceBean;
import com.irdstudio.efp.esb.common.client.resp.EsbRespSysHeadBean;
import com.irdstudio.efp.esb.common.constant.dxm.DxmConstant;
import com.irdstudio.efp.esb.service.bo.req.hj.ReqCompensationBean;
import com.irdstudio.efp.esb.service.client.ESBClientFactory;
import com.irdstudio.efp.esb.service.client.impl.LhxESBBeanCreator;
import com.irdstudio.efp.esb.service.facade.hj.PushCompensationDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * 百度逾期代偿 百度代偿多借多贷数据推送到互联网金融平台: <br>
 * <p>
 * 0.1:caoxin:2019/4/2 15:41: TODO: <br>
 *
 * @author caoxin
 * @version 0.1
 * @date 2019/4/2 15:41
 * @since 2019/4/2 15:41
 */
@Service("pushCompensationDataService")
public class PushCompensationDataServiceImpl implements PushCompensationDataService {
    /** 日志*/
    private Logger logger = LoggerFactory.getLogger(PushCompensationDataServiceImpl.class);
    /** 消息模板*/
    private final String msgTemplate = "message{ }";
    /**
     * 百度逾期代偿 百度代偿多借多贷数据推送到互联网金融平台: <br>
     *
     * 0.1:caoxin:2019/4/2 15:34: TODO: <br>
     * @author caoxin
     * @return
     * @since 2019/4/2 15:34
     * @date 2019/4/2 15:34
     * @version 0.1
     */
    @Override
    public boolean pushCompensationDataToInternetFinancePlatform(ReqCompensationBean reqCompensationBean) {
        // 结果返回
        boolean result = false;
        try {
            logger.info("开始推送====+++====> 逾期代偿【多借多贷数据】 到互联网金融平台<====+++====",msgTemplate);
            logger.info("====+++====>推送数据为<====+++====",msgTemplate);
            logger.info(JSONObject.toJSONString(reqCompensationBean),msgTemplate);
            EsbRespServiceBean esbRespServiceBean = ESBClientFactory.buildClient().withBody(reqCompensationBean)
                    .withTradeNo(DxmConstant.TRADE_NO_30210003)
                    .withScene(DxmConstant.SCENE_01)
                    .withESBBeanFactory(LhxESBBeanCreator.getINSTANCE()).create().sendAndReceive();
            // caoxin  通过系统头判断是否成功
            EsbRespSysHeadBean sysHead =
                    esbRespServiceBean.getSysHead();
            System.out.println("sysHead"+sysHead);
//            result = Boolean.valueOf(sysHead.getRetSt());
        }catch (ESBException e) {
            logger.error("====+++====>逾期代偿推送接口调用失败<====+++====",msgTemplate);
            logger.error("====+++====>错误信息>====+++====",msgTemplate);
            logger.error(e.getMessage(),msgTemplate);
            logger.error("====+++====>错误信息调用栈>====+++====",msgTemplate);
            e.printStackTrace();
        }
        return result;
    }
}
